#ifndef _RSCMD_QUE_H_
#define _RSCMD_QUE_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// 指令缓存数大于信号量个数，防止即时指令一直阻塞添加不进来
#define MAX_QUE_LEN 12

typedef struct
{
    int chnId;                  // channel ID
    unsigned char cmdLen;       // actual cmd length
    unsigned char cmdData[32];  // slave id, func code, addr
} INSTCMD;

typedef enum
{
    RTU_TYPE = 0,
    INST_TYPE = 1,
} RS485CMDTYPE;

typedef enum
{
    WAITING_SEND = 0,
    WIATING_REC = 1,
} RS485CMDSENDSTATE;

typedef struct
{
    RS485CMDTYPE type;        // 0: signal status query, 1: instaneous command
    RS485CMDSENDSTATE state;  // 0: to be sent; 1: waiting
    char sigName[128];
    uint16_t timeout_count;
    INSTCMD instCmd;
} RSRTUCMD;

extern int RsCmdQueIsFull();
extern int RsCmdQueReset();
extern int RsCmdQueIsEmpty();
extern RSRTUCMD* RsCmdQuePeek();
extern short RsCmdEnqueue(RSRTUCMD element);
extern short RsCmdDequeue(RSRTUCMD* pElement);
extern int RsCmdQueSize();

#ifdef __cplusplus
}
#endif

#endif
